/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package asfabdesk.dominio;

import java.io.Serializable;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;

/**
 *
 * @author Marco Aurélio
 */
@Entity
@Table(name = "CONVENIOS")
@NamedQueries(value = {
    @NamedQuery(name = "ConvenioPorNome", query = "SELECT c FROM Convenio c WHERE c.nome LIKE (?) AND c.deletado=false"),
    @NamedQuery(name = "ConveniosPorNomeEmpresa", query = "SELECT c FROM Convenio c WHERE c.empresa.nomeFantasia LIKE (?)"),
    @NamedQuery(name = "ConveniosPorRazaoSocial", query = "SELECT c FROM Convenio c WHERE c.empresa.razaoSocial LIKE (?)"),
    @NamedQuery(name = "ConveniosPorCNPJ", query = "SELECT c FROM Convenio c WHERE c.empresa.cnpj LIKE (?)"),
    @NamedQuery(name = "ConveniosPorDescricao", query = "SELECT c FROM Convenio c WHERE c.descricao LIKE (?)"),
    @NamedQuery(name = "ConveniosPorServico", query = "SELECT c FROM Convenio c WHERE c.empresa.tipoServico=? order by c.nome"),
    @NamedQuery(name = "ConveniosPorServicoTipoPagamento", query = "SELECT c FROM Convenio c WHERE c.empresa.tipoServico=? and c.formaPgt=? order by c.nome"),
    @NamedQuery(name = "ConveniosPorTipoPagamento", query = "SELECT c FROM Convenio c WHERE c.formaPgt=? order by c.nome"),
    @NamedQuery(name = "ConveniosPorStatus", query = "SELECT c FROM Convenio c WHERE c.status=? order by c.nome"),
    @NamedQuery(name = "ConveniosPorServicoStatus", query = "SELECT c FROM Convenio c WHERE c.empresa.tipoServico=? and c.status=? order by c.nome"),
    @NamedQuery(name = "ConveniosPorServicoTipoPagamentoStatus", query = "SELECT c FROM Convenio c WHERE c.empresa.tipoServico=? and c.formaPgt=? and c.status=? order by c.nome"),
    @NamedQuery(name = "ConveniosPorTipoPagamentoStatus", query = "SELECT c FROM Convenio c WHERE c.formaPgt=? and c.status=? order by c.nome")
})
public class Convenio implements Serializable {

    @Id
    @GeneratedValue
    private long id;
    private String nome;
    private boolean status = true;
    private int formaPgt; // 0=sem pagamento ,1=folha, 2=asfab , 3=empresa ,
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date dataInicio;
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date dataTermino;
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date dataRegistro;
    private int carencia; // em meses
    private double valor;
    private String descricao;
    private boolean deletado;
    @JoinColumn(name = "EMPRESAS_CONVENIADAS", referencedColumnName = "id")
    @ManyToOne
    private EmpresaConveniada empresa;
    @JoinColumn(name = "USUARIOS", referencedColumnName = "id")
    @ManyToOne
    private Usuario usuarioCadastrante; // funcionario ASFAB

    public Convenio() {
    }

    public int getCarencia() {
        return carencia;
    }

    public void setCarencia(int carencia) {
        this.carencia = carencia;
    }

    public Date getDataInicio() {
        return dataInicio;
    }

    public void setDataInicio(String dataInicio) {
        try {
            this.dataInicio = new Data().ConverteDataStringDate(dataInicio);
        } catch (Exception ex) {
            Logger.getLogger(Convenio.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public Date getDataRegistro() {
        return dataRegistro;
    }

    public void setDataRegistro(Date dataRegistro) {
        this.dataRegistro = dataRegistro;
    }

    public Date getDataTermino() {
        return dataTermino;
    }

    public void setDataTermino(String dataTermino) {
        try {
            this.dataTermino = new Data().ConverteDataStringDate(dataTermino);
        } catch (Exception ex) {
            Logger.getLogger(Convenio.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public int getFormaPgt() {
        return formaPgt;
    }

    public void setFormaPgt(int formaPgt) {
        this.formaPgt = formaPgt;
    }

    public String getNome() {
        return nome;
    }

    public void setNome(String nome) {
        this.nome = nome;
    }

    public boolean isStatus() {
        return status;
    }

    public void setStatus(boolean status) {
        this.status = status;
    }

    public boolean isDeletado() {
        return deletado;
    }

    public void setDeletado(boolean deletado) {
        this.deletado = deletado;
    }

    public String getDescricao() {
        return descricao;
    }

    public void setDescricao(String descricao) {
        this.descricao = descricao;
    }

    public EmpresaConveniada getEmpresa() {
        return empresa;
    }

    public void setEmpresa(EmpresaConveniada empresa) {
        this.empresa = empresa;
    }

    public String getObs() {
        return descricao;
    }

    public void setObs(String obs) {
        this.descricao = obs;
    }

    public double getValor() {
        return valor;
    }

    public void setValor(double valor) {
        this.valor = valor;
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public Usuario getUsuarioCadastrante() {
        return usuarioCadastrante;
    }

    public void setUsuarioCadastrante(Usuario usuarioCadastrante) {
        this.usuarioCadastrante = usuarioCadastrante;
    }
}
